﻿
Public Class ClsPerson

    Dim Person_HN As String = ""
    Dim Person_Fname As String = ""
    Dim Person_Lname As String = ""
    Dim Person_CID As String = ""
    Dim Person_Birthday As String = ""
    Dim Person_Pname As String = ""
    Dim Person_Age As String
    Dim Person_Sex As String
    Dim Person_Race As String
    Dim Person_Nation As String
    Dim Person_MStatus As String
    Dim Person_Ocupaton As String
    Dim Person_TypeArea As String
    Dim Mysql As New ClsSQLhelper
    Dim Strsql As String
    Property Pname() As String
        Get
            Pname = Person_Pname
        End Get
        Set(ByVal value As String)
            Person_Pname = value
        End Set
    End Property
    Property Fname() As String
        Get
            Fname = Person_Fname
        End Get
        Set(ByVal value As String)
            Person_Fname = value
        End Set
    End Property
    Property Lname() As String
        Get
            Lname = Person_Lname
        End Get
        Set(ByVal value As String)
            Person_Lname = value
        End Set
    End Property
    Property CID() As String
        Get
            CID = Person_CID
        End Get
        Set(ByVal value As String)
            Person_CID = value
        End Set
    End Property
    Property HN() As String
        Get
            HN = Person_HN
            If HN = "" Then HN = "ไม่ระบุ"
        End Get
        Set(ByVal value As String)
            Person_HN = value
        End Set
    End Property
    Property BirthDay() As String
        Get
            BirthDay = Person_Birthday
            If BirthDay = "" Then BirthDay = "ไม่ระบุ"
        End Get
        Set(ByVal value As String)
            Person_Birthday = value
        End Set
    End Property
    Property Age() As String
        Get
            If Person_Age = "" Then
                Age = "ไม่ระบุ"
                Exit Property
            End If
            Dim StrYear As String
            Dim StrMonth As String
            Dim Str_Curr_Year As String
            Dim Str_Curr_Month As String

            StrYear = Mid(Person_Birthday, 1, 4)
            StrMonth = Mid(Person_Birthday, 5, 2)

            Str_Curr_Year = Now.Year
            Str_Curr_Month = Now.Month

            Age = Val(Str_Curr_Year) - Val(StrYear) & " ปี  "
            If Str_Curr_Year = StrYear Then
                Age = Age & Val(Str_Curr_Month) - Val(StrMonth) & " เดือน"
            Else
                Age = Age & (12 - Val(StrMonth)) + Val(Str_Curr_Month) & " เดือน"
            End If
        End Get
        Set(ByVal value As String)
            Person_Age = value
        End Set
    End Property
    Property Sex() As String
        Get
            Select Case Person_Sex

                Case 1
                    Sex = "ชาย"
                Case 2
                    Sex = "หญิง"
                Case Else
                    Sex = "ไม่ได้ระบุ"
            End Select
        End Get
        Set(ByVal value As String)
            Person_Sex = value
        End Set
    End Property
    Property Nation() As String
        Get
            Dim StrSQLNationality As String = "select name from nationality where   nationality = '" & Person_Nation & "'"
            If Person_Nation = "099" Then
                Nation = "ไทย"
            Else
                Nation = Mysql.MySQLExecuteScalar(StrSQLNationality, "hos")
                If Nation = "" Then
                    Nation = "ไม่ระบุ"
                End If
            End If

        End Get
        Set(ByVal value As String)
            Person_Nation = value
        End Set
    End Property
    Property Race() As String
        Get
            Dim StrSQLNationality As String = "select name from nationality where   nationality = '" & Person_Race & "'"
            If Person_Race = "099" Then
                Race = "ไทย"
            Else
                Race = Mysql.MySQLExecuteScalar(StrSQLNationality, "hos")
                If Race = "" Then
                    Race = "ไม่ระบุ"
                End If
            End If

        End Get
        Set(ByVal value As String)
            Person_Race = value
        End Set
    End Property
    Property MStatus() As String
        Get
            Select Case Person_MStatus


                Case 1
                    MStatus = "โสด"
                Case 2
                    MStatus = "คู่"
                Case 3
                    MStatus = "ม่าย"
                Case 4
                    MStatus = "หย่า"
                Case 5
                    MStatus = "แยก"
                Case 6
                    MStatus = "สมณะ"
                Case 9
                    MStatus = "ไม่ทราบ"
                Case Else
                    MStatus = "ไม่ได้ระบุ"

            End Select

        End Get
        Set(ByVal value As String)
            Person_MStatus = value
        End Set
    End Property
    Property Ocupaton() As String
        Get

            Dim StrSQLOccupation As String = "select name from occupation where occupation = '" & Person_Ocupaton & "'"
            Ocupaton = Mysql.MySQLExecuteScalar(StrSQLOccupation, "hos")
            If Ocupaton = "" Then
                Ocupaton = "ไม่ระบุ"
            End If

        End Get
        Set(ByVal value As String)
            Person_Ocupaton = value
        End Set
    End Property
    Property TypeArea() As String
        Get
            Select Case Person_TypeArea
                Case 0
                    TypeArea = "อยู่ในเขตรับผิดชอบแต่ไม่มีชื่อในทะเบียนบ้าน เช่น คนเร่ร่อน ไร้ที่อยู่"
                Case 1
                    TypeArea = "มีชื่อในทะเบียนบ้าน และอยู่อาศัยจริง"
                Case 2
                    TypeArea = "มีชื่อในทะเบียนบ้านแต่ไม่ได้อยู่อาศัย"
                Case 3
                    TypeArea = "ไม่มีชื่อในทะเบียนบ้านแต่มาอยู่อาศัย"
                Case 4
                    TypeArea = "บุคคลนอกเขต"
                Case Else
                    TypeArea = "ไม่ได้ระบุ"


            End Select

        End Get
        Set(ByVal value As String)
            Person_TypeArea = value
        End Set
    End Property
    Sub Get_NHSO_Profile(ByVal PID As String)
        Try
            Strsql = "Select m_person.*,Concat(m_person.NAME,'  ',m_person.LNAME) as NAME,DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(m_person.BIRTH, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(m_person.BIRTH, '00-%m-%d')) AS AGE  from m_person where pid = '" & PID & "'"
            Dim DT_Person As New DataTable
            DT_Person = Mysql.GetMYSQLDataTable(Strsql, "m_person")
            If DT_Person.Rows.Count = 0 Then
                'MsgBox("ไม่พบข้อมูล", MsgBoxStyle.Exclamation)
                Person_HN = ""
                Person_Pname = ""
                Person_Fname = "ไม่พบข้อมูล"
                Person_Lname = ""
                Person_CID = "0000000000000"
                Person_Birthday = ""
                Person_Age = ""
                Person_Sex = ""
                Person_Race = ""
                Person_Nation = ""
                Person_MStatus = ""
                Person_Ocupaton = ""
                Person_TypeArea = ""
                Exit Sub
            End If
            Person_HN = DT_Person.Rows(0).Item("HN").ToString
            Person_Pname = DT_Person.Rows(0).Item("PRENAME").ToString
            Person_Fname = DT_Person.Rows(0).Item("NAME").ToString
            Person_Lname = DT_Person.Rows(0).Item("LNAME").ToString
            Person_CID = DT_Person.Rows(0).Item("CID").ToString
            Person_Birthday = DT_Person.Rows(0).Item("BIRTH").ToString
            Person_Age = DT_Person.Rows(0).Item("AGE").ToString
            Person_Sex = DT_Person.Rows(0).Item("SEX").ToString
            Person_Race = DT_Person.Rows(0).Item("RACE").ToString
            Person_Nation = DT_Person.Rows(0).Item("NATION").ToString
            Person_MStatus = DT_Person.Rows(0).Item("MSTATUS").ToString
            Person_Ocupaton = DT_Person.Rows(0).Item("OCCUPA").ToString
            Person_TypeArea = DT_Person.Rows(0).Item("MSTATUS").ToString
        Catch ex As Exception
            MsgBox(ex.Message())
        End Try

    End Sub
    ReadOnly Property Get_Person_FullName_with_PName() As String
        Get
            Get_Person_FullName_with_PName = Person_Pname & Person_Fname & " " & Person_Lname
        End Get
    End Property
    ReadOnly Property Get_Person_FullName() As String
        Get
            Get_Person_FullName = Person_Fname & " " & Person_Lname
        End Get
       
    End Property
    ReadOnly Property Get_Person_FormatCID() As String
        Get
            Get_Person_FormatCID = Pn_Framework.FormatCID(Person_CID)
        End Get

    End Property
End Class
